package com.lcxw.hxzb.friendcircle.project.system.controller;

import java.util.List;

import com.lcxw.hxzb.friendcircle.project.system.domain.YwpdDynamic;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lcxw.hxzb.friendcircle.project.system.domain.YwpdHistory;
import com.lcxw.hxzb.friendcircle.project.system.service.IYwpdHistoryService;
import com.lcxw.hxzb.friendcircle.framework.web.controller.BaseController;
import com.lcxw.hxzb.friendcircle.framework.web.domain.AjaxResult;
import com.lcxw.hxzb.friendcircle.framework.web.page.TableDataInfo;


/**
 * 用户足迹Controller
 *
 * @author theme
 * @date 2020-07-28
 */
@Api(description = "用户足迹Controller")
@RestController
@RequestMapping("/system/history")
public class YwpdHistoryController extends BaseController {

    @Autowired
    private IYwpdHistoryService ywpdHistoryService;
    @Autowired
    private IYwpdDynamicService ywpdDynamicService;

    /**
     * 谁看了我 传 memberId
     */
    @ApiOperation("谁看了我")
    @PostMapping("/whoLookedAtMe")
    public TableDataInfo whoLookedAtMe(@RequestBody YwpdHistory ywpdHistory) {
        startPage();
        List<YwpdHistory> list = ywpdHistoryService.selectYwpdHistoryList(ywpdHistory);
        for (int i = 0; i < list.size(); i++) {
            YwpdHistory history = list.get(i);
            YwpdDynamic user = ywpdDynamicService.queryAllUser(history.getUserId());
            history.setImgUrl(user.getImgUrl());
            history.setSex(user.getSex());
            history.setAge(user.getAge());
            history.setNickName(user.getNickName());
            history.setFreezeStatus(user.getFreezeStatus());
        }
        return getDataTable(list);
    }

    /**
     * 我看了谁
     * 传 userId
     * whoDidISee
     */


    /**
     * 删除用户足迹
     */
    @ApiOperation("删除用户足迹")
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody YwpdHistory ywpdHistory) {
        ywpdHistory.setStatus((long) 0);
        List<YwpdHistory> historyList = ywpdHistoryService.selectYwpdHistory(ywpdHistory);
        for (int i = 0; i < historyList.size(); i++) {
            YwpdHistory history = historyList.get(i);
            history.setStatus((long) 1);
            ywpdHistoryService.updateYwpdHistory(history);
        }
        return AjaxResult.success();
    }
}
